package com.xgimi.open.skill.datamanager.biz.common.aop;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author coderzpw.zhang
 * @version 1.0
 * @description 日志
 * @date 2023/2/10 1:30
 */
@Slf4j
@Component
@Aspect // 声明该类为一个切面类
public class LogAspect {

    // 定义切点
    @Pointcut(value = "execution(* com.xgimi.open.skill.datamanager.service.impl..*.*(..))")
    public void logPointCut() {
    }

    // 环绕通知
    @Around("logPointCut()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("入参: {}", JSON.toJSONString(proceedingJoinPoint.getArgs()));
        long start = System.currentTimeMillis();
        Object result = proceedingJoinPoint.proceed();
        log.info("出参: {}", JSON.toJSONString(result));
        log.info("Time Cost: {} ms", System.currentTimeMillis() - start);
        return result;
    }

}
